<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="/webjars/bootstrap/3.3.7/css/bootstrap.min.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>


    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
    <style>

    </style>
</head>
<body>
        <div id="vuebox">
            <div class="container">
                <div class="row" style="margin-top: 50px;">
                    <div class="col-md-6">
                        <form class="form-inline" role="form" style="padding-left: 250px;">
                            <div class="form-group" style="padding-left: 20px;">
                                <label>图书分类:</label>
                                <select class="form-control" v-model="categoryId"><!--骆驼命名法-->
                                    <option value="0">全部</option>
                                    <option v-for="item in categoryList.data" :value="item.id">{{item.name}}</option>
                                </select>
                            </div>
                            <div class="form-group" style="padding-left: 20px;">
                                <button type="button" class="btn btn-primary" @click="selectEntry(1)">查询</button>
                            </div>

                        </form>
                    </div>
                    <div class="col-md-4 text-right">
                        <a href="add_entry.html" class="btn btn-primary">新增电子图书</a>
                    </div>
                </div>

                <br/>
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>图书编号</th>
                        <th>图书名称</th>
                        <th>图书摘要</th>
                        <th>上传人</th>
                        <th>上传时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="item in entryList.data.list">
                        <td>{{item.id}}</td>
                        <td>{{item.title}}</td>
                        <td>{{item.summary}}</td>
                        <td>{{item.uploaduser}}</td>
                        <td>{{item.createdate}}</td>
                        <td>
                            <button class="btn btn-success" @click="to_update_entry(item.id)">修改</button>
                            <button class="btn btn-danger" @click="deleteEntry(item.id)">删除</button>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <br/>

               <!-- <div class="text-center">
            <ul class="pagination">
                <li v-show="entryList.data.hasPreviousPage">
                    <a href="" @click.stop="selectEntry(entryList.data.perPage)">&laquo;</a>
                </li>
                <li :class="{active:entryList.data.pageNum==i}" v-for="i of entryList.data.navigatepageNums">
                    <a href="" @click.stop= "selectEntry(i)">{{i}}</a>
                </li>
                <li v-show="entryList.data.hasNextPage">
                    <a href="" @click.stop="selectEntry(entryList.data.nextPage)">&raquo;</a>
                </li>
            </ul>
                </div>-->

                <div class="text-center">
                    <ul class="pagination">
                        <li v-show="entryList.data.hasPreviousPage">
                            <a href="#" @click.stop="selectEntry(entryList.data.perPage)">&laquo;</a>
                        </li>
                        <li :class="{active:entryList.data.pageNum==i}" v-for="i of entryList.data.navigatepageNums">
                            <a href="#" @click.stop="selectEntry(i)">{{i}}</a>
                        </li>
                        <li v-show="entryList.data.hasNextPage">
                            <a href="#" @click.stop="selectEntry(entryList.data.nextPage)">&raquo;</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
</body>
</html>
<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            categoryList:{},
            categoryId:"0",
            entryList:{},
        },
        methods:{
            selectEntry:function (pageNum) {
                axios.get("/selectEntry",{params:{categoryId: this.categoryId,pageNum:pageNum}})
                    .then(res=>{this.entryList=res.data});
            }
        },
        mounted(){
            axios.get("/getCategoryList").then(res=>{this.categoryList=res.data});
            this.selectEntry(1);
        }
    })
</script>